home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / bgui11b.lha / ARexxClass / arexxdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-25  |  9.6 KB  |  260 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc arexxdemo.c -proto -mi -ms -lbgui -larexxclass.o
  3. quit
  4. */
  5. /*
  6. **         $RCSfile: arexxdemo.c,v $
  7. **      Description: Simple demonstration of the arexx class.
  8. **        Copyright: (C) Copyright 1994 Jaba Development.
  9. **                   (C) Copyright 1994 Jan van den Baard.
  10. **                   All Rights Reserved.
  11. **
  12. **          $Author: jaba $
  13. **        $Revision: 1.1 $
  14. **            $Date: 1994/09/25 14:31:28 $
  15. **/
  16.  
  17. #include <libraries/bgui.h>
  18. #include <libraries/bgui_macros.h>
  19. #include <libraries/gadtools.h>
  20.  
  21. #include <dos/dos.h>
  22. #include <dos/datetime.h>
  23.  
  24. #include <clib/alib_protos.h>
  25.  
  26. #include <proto/exec.h>
  27. #include <proto/bgui.h>
  28. #include <proto/intuition.h>
  29. #include <proto/dos.h>
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34.  
  35. #include "arexxclass.h"
  36.  
  37. /*
  38. **      ARexx class base variable.
  39. **/
  40. Class                           *ARexxClass;
  41.  
  42. /*
  43. **      Protos for the arexx command functions.
  44. **/
  45. VOID rx_Name( REXXARGS *, struct RexxMsg * );
  46. VOID rx_Version( REXXARGS *, struct RexxMsg * );
  47. VOID rx_Author( REXXARGS *, struct RexxMsg * );
  48. VOID rx_Date( REXXARGS *, struct RexxMsg * );
  49.  
  50. /*
  51. **      The following commands are
  52. **      valid for this demo.
  53. **/
  54. REXXCOMMAND Commands[] = {
  55.         "NAME",                 NULL,                   rx_Name,
  56.         "VERSION",              NULL,                   rx_Version,
  57.         "AUTHOR",               NULL,                   rx_Author,
  58.         "DATE",                 "SYSTEM/S",             rx_Date,
  59. };
  60.  
  61. /*
  62. **      NAME
  63. **/
  64. VOID rx_Name( REXXARGS *ra, struct RexxMsg *rxm )
  65. {
  66.         /*
  67.         **      Simply return the program name.
  68.         **/
  69.         ra->ra_Result = "ARexxDemo";
  70. }
  71.  
  72. /*
  73. **      VERSION
  74. **/
  75. VOID rx_Version( REXXARGS *ra, struct RexxMsg *rxm )
  76. {
  77.         /*
  78.         **      Simply return the program version.
  79.         **/
  80.         ra->ra_Result = "1.0";
  81. }
  82.  
  83. /*
  84. **      AUTHOR
  85. **/
  86. VOID rx_Author( REXXARGS *ra, struct RexxMsg *rxm )
  87. {
  88.         /*
  89.         **      Simply return the authors name.
  90.         **/
  91.         ra->ra_Result = "Jan van den Baard";
  92. }
  93.  
  94. /*
  95. **      Buffer for the system date.
  96. **/
  97. UBYTE                   systemDate[ 10 ];
  98.  
  99. /*
  100. **      DATE
  101. **/
  102. VOID rx_Date( REXXARGS *ra, struct RexxMsg *rxm )
  103. {
  104.         struct DateTime                 dt;
  105.  
  106.         /*
  107.         **      SYSTEM switch specified?
  108.         **/
  109.         if ( ! ra->ra_ArgList[ 0 ] )
  110.                 /*
  111.                 **      No. Simply return the compilation date.
  112.                 **/
  113.                 ra->ra_Result = "25-09-94";
  114.         else {
  115.                 /*
  116.                 **      Compute system date.
  117.                 **/
  118.                 DateStamp(( struct DateStamp * )&dt );
  119.                 dt.dat_Format  = FORMAT_CDN;
  120.                 dt.dat_StrDate = systemDate;
  121.                 dt.dat_Flags   = 0;
  122.                 dt.dat_StrDay  = NULL;
  123.                 dt.dat_StrTime = NULL;
  124.                 DateToStr(&dt);
  125.                 /*
  126.                 **      And return it.
  127.                 **/
  128.                 ra->ra_Result = systemDate;
  129.         }
  130. }
  131.  
  132. /*
  133. **      Object ID's.
  134. **/
  135. #define ID_QUIT                 1
  136.  
  137. int main( int argc, char *argv[] )
  138. {
  139.         struct Window           *window;
  140.         Object                  *WO_Window, *GO_Quit, *AO_Rexx;
  141.         ULONG                    signal = 0, rxsig = 0L, rc, sigrec;
  142.         BOOL                     running = TRUE;
  143.  
  144.         /*
  145.         **      Initialize the ARexxClass.
  146.         **/
  147.         if ( ARexxClass = InitARexxClass()) {
  148.                 /*
  149.                 **      Create host object.
  150.                 **/
  151.                 if ( AO_Rexx = NewObject( ARexxClass, NULL, AC_HostName, "RXDEMO", AC_CommandList, Commands, TAG_END )) {
  152.                         /*
  153.                         **      Create the window object.
  154.                         **/
  155.                         WO_Window = WindowObject,
  156.                                 WINDOW_Title,           "ARexx Demo",
  157.                                 WINDOW_SizeGadget,      FALSE,
  158.                                 WINDOW_RMBTrap,         TRUE,
  159.                                 WINDOW_MasterGroup,
  160.                                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  161.                                                 StartMember,
  162.                                                         InfoFixed( NULL,
  163.                                                                    ISEQ_C "This is a small demonstration of\n"
  164.                                                                    "the ARexx BOOPSI class. Please run the\n"
  165.                                                                    ISEQ_B "Demo.rexx" ISEQ_N " script and see\n"
  166.                                                                    "what happens",
  167.                                                                    NULL,
  168.                                                                    4 ),
  169.                                                 EndMember,
  170.                                                 StartMember,
  171.                                                         HGroupObject,
  172.                                                                 VarSpace( 50 ),
  173.                                                                 StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  174.                                                                 VarSpace( 50 ),
  175.                                                         EndObject,
  176.                                                 EndMember,
  177.                                         EndObject,
  178.                         EndObject;
  179.  
  180.                         /*
  181.                         **      Object created OK?
  182.                         **/
  183.                         if ( WO_Window ) {
  184.                                 /*
  185.                                 **      Assign a key to the button.
  186.                                 **/
  187.                                 if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  188.                                         /*
  189.                                         **      try to open the window.
  190.                                         **/
  191.                                         if ( window = WindowOpen( WO_Window )) {
  192.                                                 /*
  193.                                                 **      Obtain wait masks.
  194.                                                 **/
  195.                                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  196.                                                 GetAttr( AC_RexxPortMask, AO_Rexx, &rxsig );
  197.                                                 /*
  198.                                                 **      Event loop...
  199.                                                 **/
  200.                                                 do {
  201.                                                         sigrec = Wait( signal | rxsig );
  202.  
  203.                                                         /*
  204.                                                         **      ARexx event?
  205.                                                         **/
  206.                                                         if ( sigrec & rxsig )
  207.                                                                 DoMethod( AO_Rexx, ACM_HANDLE_EVENT );
  208.  
  209.                                                         /*
  210.                                                         **      Window event?
  211.                                                         **/
  212.                                                         if ( sigrec & signal ) {
  213.                                                                 /*
  214.                                                                 **      Handle events.
  215.                                                                 **/
  216.                                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  217.                                                                         /*
  218.                                                                         **      Evaluate return code.
  219.                                                                         **/
  220.                                                                         switch ( rc ) {
  221.  
  222.                                                                                 case    WMHI_CLOSEWINDOW:
  223.                                                                                 case    ID_QUIT:
  224.                                                                                         running = FALSE;
  225.                                                                                         break;
  226.                                                                         }
  227.                                                                 }
  228.                                                         }
  229.                                                 } while ( running );
  230.                                         } else
  231.                                                 puts ( "Could not open the window" );
  232.                                 } else
  233.                                         puts( "Could not assign gadget keys" );
  234.                                 DisposeObject( WO_Window );
  235.                         } else
  236.                                 puts( "Could not create the window object" );
  237.                         DisposeObject( AO_Rexx );
  238.                 } else
  239.                         puts( "Could not create the ARexx host." );
  240.                 FreeARexxClass( ARexxClass );
  241.         } else
  242.                 puts( "Unable to setup the arexx class" );
  243.  
  244.         return( 0 );
  245. }
  246.  
  247. #ifdef _DCC
  248. int wbmain( struct WBStartup *wbs )
  249. {
  250.         return( main( 0, NULL ));
  251. }
  252. #endif
  253.  
  254. /*
  255.  *      $Log: arexxdemo.c,v $
  256.  * Revision 1.1  1994/09/25  14:31:28  jaba
  257.  * Initial revision
  258.  *
  259.  */
  260.